<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Loader
 * This class is utility to help load class when in need
 *
 * @author thuongnh
 */
class Loader {

    public static function loadClass($className) {
        if (Loader::existClass($className)) {
            if (file_exists("../app/" . $className . ".php")) {
                require_once("../app/" . $className . ".php");
            } else if (file_exists("../app/controller/" . $className . ".php")) {
                require_once("../app/controller/" . $className . ".php");
            } else if (file_exists("../app/model/" . $className . ".php")) {
                require_once("../app/model/" . $className . ".php");
            } else if (file_exists("../lib/" . $className . ".php")) {
                require_once("../lib/" . $className . ".php");
            }
        }
    }

    public static function loadClassModule($module, $className) {
        if (file_exists("../app/$module/controller/" . $className . ".php")) {
            require_once("../app/$module/controller/" . $className . ".php");
        } else if (file_exists("../app/$module/model/" . $className . ".php")) {
            require_once("../app/$module/model/" . $className . ".php");
        }
    }

    public static function existClass($className) {
        if ($className != null && $className != "") {
            if (file_exists("../app/" . $className . ".php")) {
                return true;
            } else if (file_exists("../app/controller/" . $className . ".php")) {
                return true;
            } else if (file_exists("../app/model/" . $className . ".php")) {
                return true;
            } else if (file_exists("../lib/" . $className . ".php")) {
                return true;
            }
        }
        return false;
    }

    public static function existClassModule($module, $className) {
        if (file_exists("../app/$module/controller/" . $className . ".php")) {
            return true;
        } else if (file_exists("../app/$module/model/" . $className . ".php")) {
            return true;
        }
    }

}

?>
